package org.example.adservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.example.adservice.mapper.AdMapper;
import org.example.adservice.service.AdService;
import org.example.pojo.Ad;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 广告服务实现类
 */
@Service
@RequiredArgsConstructor
public class AdServiceImpl implements AdService {

    private final AdMapper adMapper;

    @Override
    public Ad createAd(Ad ad) {
        adMapper.insert(ad);
        return ad;
    }

    @Override
    public Ad updateAd(Integer id, Ad ad) {
        ad.setId(id);
        adMapper.updateById(ad);
        return ad;
    }

    @Override
    public boolean deleteAd(Integer id) {
        return adMapper.deleteById(id) > 0;
    }

    @Override
    public Ad getAdById(Integer id) {
        return adMapper.selectById(id);
    }

    @Override
    public List<Ad> getAllAds() {
        return adMapper.selectList(new QueryWrapper<>());
    }
}